//
//  CaseWashPageController.m
//  WashForU
//
//  Created by 王俊 on 15/11/25.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "CaseWashPageController.h"


@implementation CaseWashPageController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self customViewSetUp];
    [self customConstrainsAdd];
    [self targetAdd];
}
/*****************添加视图组件********************/
- (void)customViewSetUp
{
    self.titleLabel.text      = @"件洗";
    self.titleLabel.font      = [UIFont CustomFont:19];
    self.titleLabel.textColor = [UIColor GrayColor_30];
    
    _layout = [[CaseWashCollectionLayout alloc]init];
    
    _collectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:_layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor clearColor];
    [_collectionView registerClass:CaseWashCollectionViewCell.self forCellWithReuseIdentifier:REUSECELLLID];
    [self.view addSubview:_collectionView];
    
    
    _springClothesButton = [[UIButton alloc]init];
    _summerClothesButton = [[UIButton alloc]init];
    _winterClothesButton = [[UIButton alloc]init];
    _indicatorView1      = [[UIView alloc]init];
    _indicatorView2      = [[UIView alloc]init];
    _indicatorView3      = [[UIView alloc]init];

    
    [self buttonSetUp :_springClothesButton textInfo:@"春/秋装" fontSize:17];
    [self buttonSetUp :_summerClothesButton textInfo:@"夏装"    fontSize:17];
    [self buttonSetUp :_winterClothesButton textInfo:@"冬装"    fontSize:17];
    [self indicatorSet:_indicatorView1];
    [self indicatorSet:_indicatorView2];
    [self indicatorSet:_indicatorView3];
    
    _springClothesButton.enabled = false;
    _indicatorView1.hidden       = false;

    
    
}
/*******************添加约束**********************/
- (void)customConstrainsAdd
{
    [_springClothesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(45);
        make.width.mas_equalTo(SCREENWIDTH/3);
        make.top.equalTo(self.upView.mas_bottom);
        make.leading.equalTo(self.view);
    }];
    [_summerClothesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.top.equalTo(self.springClothesButton);
        make.leading.equalTo(self.springClothesButton.mas_trailing);
    }];
    [_winterClothesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.top.equalTo(self.springClothesButton);
        make.leading.equalTo(self.summerClothesButton.mas_trailing);
    }];
    [_indicatorView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(5);
        make.leading.trailing.bottom.equalTo(self.springClothesButton);
    }];
    [_indicatorView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.indicatorView1);
        make.leading.trailing.bottom.equalTo(self.summerClothesButton);
    }];
    [_indicatorView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.indicatorView1);
        make.trailing.leading.bottom.equalTo(self.winterClothesButton);
    }];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(self.view);
        make.top.equalTo(self.springClothesButton.mas_bottom);
    }];
}
/*****************设置Button格式******************/
- (void)buttonSetUp:(UIButton*) button textInfo:(NSString *) textInfo fontSize:(CGFloat) size
{
    [button setTitle:textInfo forState:UIControlStateNormal];
    [button setTitleColor:[UIColor GrayColor_88] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor CustomLightBlue] forState:UIControlStateDisabled];
    button.layer.borderWidth = 1;
    button.layer.borderColor = [UIColor GrayColor_244].CGColor;
    button.backgroundColor = [UIColor whiteColor];
    button.titleLabel.font = [UIFont CustomFont:17];
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:button];
}
/*****************设置Indicator******************/
- (void)indicatorSet:(UIView*) indicator
{
    indicator.backgroundColor = [UIColor CustomLightBlue];
    indicator.hidden          = true;
    [self.view addSubview:indicator];
}
/*******************添加事件**********************/
- (void)targetAdd
{
    [self.backButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_springClothesButton addTarget:self action:@selector(springClothesButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_summerClothesButton addTarget:self action:@selector(summerClothesButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_winterClothesButton addTarget:self action:@selector(winterClothesButtonClicked) forControlEvents:UIControlEventTouchUpInside];
}
- (void)springClothesButtonClicked
{
    [self resetState];
    _springClothesButton.enabled = false;
    _indicatorView1.hidden       = false;
}
- (void)summerClothesButtonClicked
{
    [self resetState];
    _summerClothesButton.enabled = false;
    _indicatorView2.hidden       = false;
 
}
- (void)winterClothesButtonClicked
{
    [self resetState];
    _winterClothesButton.enabled = false;
    _indicatorView3.hidden       = false;

}
- (void)resetState
{
    _springClothesButton.enabled = true;
    _summerClothesButton.enabled = true;
    _winterClothesButton.enabled = true;
    _indicatorView1.hidden       = true;
    _indicatorView2.hidden       = true;
    _indicatorView3.hidden       = true;
}
/************CollectioView DataSource设置**************/
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return ITEMNUMBER;
    
}

//- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
//{
//    return 1;
//}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    ClothesInfo *data = [ClothesInfo initWithTitle:@"短衬衫" andImageName:@"短衬衫" andPrice:8];
    CaseWashCollectionViewCell *cell = [_collectionView dequeueReusableCellWithReuseIdentifier:REUSECELLLID forIndexPath:indexPath];
    
    [cell setUpViewWith:data];
    
    return cell;
    
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ClothesInfo * data = [ClothesInfo initWithTitle:@"短衬衫" andImageName:@"短衬衫" andPrice:8 andDescInfo:@"洗啥不好洗这件\n太难洗了"];
    [PopUpView show:data];
}

@end



